package com.sciencep.pro.admin.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sciencep.pro.admin.system.common.util.UserUtil;
import com.sciencep.pro.common.domain.QueryRequest;
import com.sciencep.pro.common.domain.ResponseResult;
import com.sciencep.pro.common.exception.CustomException;
import com.sciencep.pro.core.domain.dto.assignment.AssignmentTo;
import com.sciencep.pro.core.domain.dto.project.ProAssignmentTO;
import com.sciencep.pro.core.domain.dto.user.UserDetail;
import com.sciencep.pro.core.service.IProAssignmentService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Slf4j
@RestController
@RequestMapping(value = "/assignment")
public class AssignmentController {

    @Autowired
    IProAssignmentService proAssignmentService;

    @Autowired
    UserUtil userUtil;

    @PostMapping(value = "/saveAssign")
    @ApiOperation(value = "分配项目",notes = "插入人员分配计划")
    public ResponseResult<Object> saveAssign(@RequestBody ProAssignmentTO proAssignment) throws CustomException {
        UserDetail userDetail = userUtil.getCurrentUserDetail();
        if(proAssignmentService.saveAssign(proAssignment,userDetail)){
            return new ResponseResult<>().success();
        }else {
            return new ResponseResult<>().failure();
        }
    }

    @PostMapping(value = "/updateReadType")
    @ApiOperation(value = "更新读取状态")
    public ResponseResult<Object> updateReadType(@RequestBody ProAssignmentTO proAssignmentTO) throws CustomException {
        UserDetail userDetail = userUtil.getCurrentUserDetail();
        if(proAssignmentService.updateReadType(proAssignmentTO,userDetail)){
            return new ResponseResult<>().success();
        }else {
            return new ResponseResult<>().failure();
        }
    }

    @GetMapping(value = "/getReviewList")
    @ApiOperation(value = "日志评审列表")
    public ResponseResult<Page<AssignmentTo>> getReviewList(QueryRequest queryRequest,AssignmentTo assignmentTo){
       return new ResponseResult<Page<AssignmentTo>>().success(proAssignmentService.getReviewList(queryRequest,assignmentTo));
    }

    @PostMapping(value = "/updateReview")
    @ApiOperation(value = "更新日志评审人")
    public ResponseResult<Object> updateReview(AssignmentTo assignmentTo){
        return new ResponseResult<>().success(proAssignmentService.updateReview(assignmentTo));
    }

}
